﻿@section header{
   
}

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a></li>
                <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a></li>
                <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

@section scripts{
    <script>
        var baseUrl = "/flow/FlowSchemes/";
        $(function () {
            initControl();
        });
        function initControl() {
            gridList();
        }
        function gridList() {
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                url: baseUrl + "GetJGridPageDataJson",
                datatype: "json",
                height: $(window).height() - 120,
                mtype: "POST",
                colModel: [
                    { label: "主键", name: "ID", hidden: true, key: true },
                    { label: '流程名称', name: 'SchemeName', align: 'left' },
                    { label: '流程分类', name: 'SchemeType', align: 'left' },
                    {
                        label: "有效", name: "Status", align: "center",
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return cellvalue == 0 ? "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-on\"></i>" : "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    { label: '添加时间', name: 'AddTime', align: 'left' }
                ],
                rowNum: 20,
                rowList: [20, 50, 100],
                pager: '#gridPager',
                sortname: 'ID',
                sortorder: "asc",
                viewrecords: true,
                autowidth: true,
                loadComplete: function () {
                    $('.ui-jqgrid-bdiv').scrollTop(0);
                    setTimeout(function () { btn_tc(); });
                }
            });
            $("#btn_search").click(function () {
                $gridList.jqGrid('setGridParam', {
                    postData: { keyword: $("#txt_keyword").val() },
                }).trigger('reloadGrid');
            });
        }
        function btn_add() {
            $.modalOpen({
                id: "Form",
                title: "新增",
                url: baseUrl + "Design",
                width: "700px",
                height: "620px",
                btn: null
            });
        }
        function btn_edit() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            console.log($("#gridList").jqGridRowValue());
            debugger;
            $.modalOpen({
                id: "Form",
                title: "修改",
                url: baseUrl + "Design?keyValue=" + keyValue,
                width: "700px",
                height: "620px",
                btn: null
            });
        }
        function btn_delete() {
            $.deleteForm({
                url: baseUrl + "DeleteForm",
                param: { keyValue: $("#gridList").jqGridRowValue().ID },
                success: function () {
                    $("#gridList").trigger("reloadGrid");
                }
            })
        }
        function btn_details() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Details",
                title: "查看",
                url: baseUrl + "Details?keyValue=" + keyValue,
                width: "700px",
                height: "620px",
                btn: null,
            });
        }
        //关闭有效触发
        function Switch(keyId) {
            $.ajax({
                url: baseUrl + "Switch?keyId=" + keyId,
                data: {},
                type: "POST",
                dataType: "json",
                async: false,
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
        function update_field(keyId, cellvalue) {
            $.ajax({
                url: baseUrl + "UpdateOrderBy?keyId=" + keyId + "&value=" + cellvalue,
                data: {},
                dataType: "json",
                type: "POST",
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
    </script>
}